const fs = require("fs");
const path = require("path");

const dirPath = path.join(__dirname,process.argv[2]);
fs.exists(dirPath,function(exists) {
    if(exists == true) {
        const stat = fs.lstatSync(dirPath);
        if(stat.isFile()) {
            fs.unlinkSync(dirPath);
        }
        else if (stat.isDirectory()){
            function del(dirPath){
                const arr = fs.readdirSync(dirPath);
                for(const i in arr) {
                    const stats = fs.statSync(dirPath+ '/' + arr[i]);
                    if(stats.isFile()) {
                        fs.unlinkSync(dirPath + '/' + arr[i]);
                    }
                    else {
                        del(dirPath + '/' + arr[i]);
                    }
                }
                fs.rmdirSync(dirPath);
            }
            del(dirPath);
        }
    }
    else {
        console.log("路径文件不存在");
    }
});